﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using TKFA.OracleDAL;
using System.Collections;


namespace FixedAssets.Module.BasicInformation
{
    public partial class FA_Employee : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //this.C1GridView1.Visible = false;
                DataTable dt = getTableOfEmp();

                this.C1GridView2.DataSource = dt;
                C1GridView2.DataBind();
            }
        }

        private DataTable getTableOfEmp()
        {
            DataTable dt = new DataTable();
            EMPLOYEE mod = new EMPLOYEE();
            dt = mod.GetList("").Tables[0];
            DataView dv = dt.DefaultView;
            dv.Sort = "USERID";
            return dv.ToTable();
        }

        protected void C1Menu1_ItemClick(object sender, C1.Web.Wijmo.Controls.C1Menu.C1MenuEventArgs e)
        {
            string strInfomation = "";
            switch (e.Item.Value)
            {
                case "GetLink"://获取人员信息
                    strInfomation = getLink();
                    break;
                case "SaveInfo"://保存人员信息
                    strInfomation = InsertEmp();
                    break;
            }

            //this.Label1.Text = strInfomation;
        }

        private string InsertEmp()
        {
            string str = "保存成功";

            //if (this.C1GridView1.Visible)
            //{
            //    DataTable dt = (DataTable)this.C1GridView1.DataSource;
            //    TKFA.Model.EMPLOYEE emp = new TKFA.Model.EMPLOYEE();
            //    EMPLOYEE mod = new EMPLOYEE();
            //    for (int i = 0; i < dt.Rows.Count; i++)
            //    {
            //        #region 对象赋值
            //        emp.ADDRESS = dt.Rows[i]["ADDRESS"].ToString();
            //        emp.BANKACCOUNT = dt.Rows[i]["BANKACCOUNT"].ToString();
            //        emp.BARCODES = dt.Rows[i]["BARCODES"].ToString();
            //        emp.BIRTHDAY = DateTime.Parse(dt.Rows[i]["BIRTHDAY"].ToString());
            //        emp.CARDID = dt.Rows[i]["CARDID"].ToString();
            //        emp.CREDITLEVEL = dt.Rows[i]["CREDITLEVEL"].ToString();
            //        emp.CREDITPERIOD = dt.Rows[i]["CREDITPERIOD"].ToString();
            //        emp.DEGREE = dt.Rows[i]["DEGREE"].ToString();
            //        emp.DUTY = dt.Rows[i]["DUTY"].ToString();
            //        emp.EMAIL = dt.Rows[i]["EMAIL"].ToString();
            //        emp.EMPGROUP = dt.Rows[i]["EMPGROUP"].ToString();
            //        emp.FOTHERAPACCTID = dt.Rows[i]["FOTHERAPACCTID"].ToString();
            //        emp.FOTHERARACCTID = dt.Rows[i]["FOTHERARACCTID"].ToString();
            //        emp.FPREAPACCTID = dt.Rows[i]["FPREAPACCTID"].ToString();
            //        emp.FPREARACCTID = dt.Rows[i]["FPREARACCTID"].ToString();
            //        emp.GENDER = dt.Rows[i]["GENDER"].ToString();
            //        emp.HIREDATE = dt.Rows[i]["HIREDATE"].ToString();
            //        emp.ISCREDITMANAGE = dt.Rows[i]["ISCREDITMANAGE"].ToString();
            //        emp.ISDETAIL = dt.Rows[i]["ISDETAIL"].ToString();
            //        emp.LEAVEDATE = dt.Rows[i]["LEAVEDATE"].ToString();
            //        emp.NAME = dt.Rows[i]["NAME"].ToString();
            //        emp.NOTE = dt.Rows[i]["NOTE"].ToString();
            //        emp.PARENT = dt.Rows[i]["PARENT"].ToString();
            //        emp.PHONE = dt.Rows[i]["PHONE"].ToString();
            //        emp.PROFESSIONALGROUP = dt.Rows[i]["PROFESSIONALGROUP"].ToString();
            //        emp.SDEPARTMENTCODE = dt.Rows[i]["SDEPARTMENTCODE"].ToString();
            //        emp.SLEVEL = dt.Rows[i]["SLEVEL"].ToString();
            //        emp.SNUMBER = dt.Rows[i]["SNUMBER"].ToString();
            //        emp.USERID = dt.Rows[i]["USERID"].ToString();
            //        emp.UUID = dt.Rows[i]["UUID"].ToString();
            //        #endregion
            //        if (mod.Add(emp))
            //        {
            //            emp = new TKFA.Model.EMPLOYEE();
            //            continue;
            //        }
            //        else
            //        {
            //            emp = new TKFA.Model.EMPLOYEE();
            //            str = "保存失败";
            //            break;

            //        }

            //    }

            //    if (str == "保存成功")
            //    {
            //        this.C1GridView1.Visible = false;
            //        DataTable dt1 = getTableOfEmp();

            //        this.C1GridView2.DataSource = dt1;
            //        C1GridView2.DataBind();
            //    }
            //}
            //else
            //{
            //    str = "没有新的人员需要保存";
            //}
            return str;
        }

        private string getLink()
        {
            string str = "获取人资人员信息成功";

            //try
            //{
            //    DataTable dt = new DataTable();
            //    //连接WebService
            //    if (dt.Rows.Count == 0)
            //    {
            //        str = "没有新的人员加入";
            //    }
            //    else
            //    {
            //        this.C1GridView1.Visible = true;
            //        this.C1GridView1.DataSource = dt;
            //        this.C1GridView1.DataBind();
            //    }
            //}
            //catch(Exception e)
            //{
            //    str = "获取信息异常";
            //}
            


            return str;
        }

        protected void C1GridView2_PageIndexChanging(object sender, C1.Web.Wijmo.Controls.C1GridView.C1GridViewPageEventArgs e)
        {
            this.C1GridView2.PageIndex = e.NewPageIndex;
            DataTable dt = getTableOfEmp();
            this.C1GridView2.DataSource = dt;
            C1GridView2.DataBind();
        }
    }
}